package com.wolfsea.scrolledfloatactionbutton.util
import android.app.Activity
import android.content.res.Resources

/**
 *@desc  屏幕工具类
 *@author liuliheng
 *@time 2021/11/14  11:12
 **/
object ScreenUtil {

    fun adapterScreen(activity: Activity, targetDp: Int, mIsVertical: Boolean) {
        //系统屏幕尺寸
        val systemDm = Resources.getSystem().displayMetrics
        //app屏幕尺寸
        val appDm = activity.application.resources.displayMetrics
        //activity屏幕尺寸
        val activityDm = activity.resources.displayMetrics
        if (mIsVertical) {
            //适配屏幕的高度
            activityDm.density = activityDm.heightPixels / targetDp.toFloat()
        } else {
            //适配屏幕的宽度
            activityDm.density = activityDm.widthPixels / targetDp.toFloat()
        }
        //适配相应比例的字体大小
        activityDm.scaledDensity = activityDm.density * (systemDm.scaledDensity / systemDm.density)
        //适配dpi
        activityDm.densityDpi = (160 * activityDm.density).toInt()
    }

    fun resetScreen(activity: Activity) {
        //系统屏幕尺寸
        val systemDm = Resources.getSystem().displayMetrics
        //app屏幕尺寸
        val appDm = activity.application.resources.displayMetrics
        //activity屏幕尺寸
        val activityDm = activity.resources.displayMetrics

        activityDm.density = systemDm.density
        activityDm.scaledDensity = systemDm.scaledDensity
        activityDm.densityDpi = systemDm.densityDpi

        appDm.density = systemDm.density
        appDm.scaledDensity = systemDm.scaledDensity
        appDm.densityDpi = systemDm.densityDpi
    }
}